package com.weixin.paleituo.view;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.text.Html;
import android.text.Spanned;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.weixin.paleituo.R;
import com.weixin.paleituo.util.UIUtils;

/**
 * Author yichao
 * Time  2018/1/10 16:31
 * Dest  ${TODO}
 */

public class RegisterProtocolPopupWindow extends PopupWindow {


    private View mLlProtocolView;
    private TextView mTvIkonw;
    private RelativeLayout mLlcontenRoot;
    private TextView mTvContent;


    public RegisterProtocolPopupWindow(Context context,String content) {
        this(context,null,content);
    }

    public RegisterProtocolPopupWindow(Context context, AttributeSet attrs,String content) {
        this(context, attrs,0,content);
    }

    public RegisterProtocolPopupWindow(Context context, AttributeSet attrs, int defStyleAttr,String content) {
        super(context, attrs, defStyleAttr);
        init(context,content);
    }

    private void init(Context context, String content) {
        mLlProtocolView = UIUtils.inflate(context, R.layout.item_register_protocol_ppwindow_layout);
        mTvIkonw = mLlProtocolView.findViewById(R.id.tv_ikonw_item_register_protocol_ppwindow_layout);
        mLlcontenRoot = mLlProtocolView.findViewById(R.id.ll_contentroot_item_register_protocol_ppwindow_layout);
        mTvContent = mLlProtocolView.findViewById(R.id.tv_protocol_content);
        Spanned result;

        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
            result = Html.fromHtml(content,Html.FROM_HTML_MODE_LEGACY);
        } else {
            result = Html.fromHtml(content);
        }

        mTvContent.setText(result);

        this.setContentView(mLlProtocolView);
        this.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
        this.setHeight(ViewGroup.LayoutParams.MATCH_PARENT);
        // 设置SelectPicPopupWindow弹出窗体可点击
        this.setFocusable(true);
        ColorDrawable dw = new ColorDrawable(0xffffff);
        this.setBackgroundDrawable(dw);
        mLlProtocolView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
        mTvIkonw.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
        mLlcontenRoot.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
    }





}
